package Exception;
import java.io.IOException;
import java.io.*;
import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) throws IOException{
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入源文件:");
        File srcFile = new File(scanner.next());
        System.out.println("请输入目标文件");
        File descFile = new File(scanner.next());
        if(!srcFile.isFile()){
            System.out.println("源文件输入错误!");
            return;
        }

        if(!descFile.getParentFile().isDirectory()){
            System.out.println("输入目标文件错误!");
            return;
        }
        //2.打开源文件将源文件里的读入目标文件
        try (InputStream inputStream = new FileInputStream(srcFile);
             OutputStream outputStream = new FileOutputStream(descFile)){
            while (true){
                int ret = inputStream.read();
                if(ret==-1){
                    break;
                }
                outputStream.write(ret);
            }
        }
    }
}
